import QtQuick 2.6

QtObject {
    property var sequence: []
    property MouseArea accept
    Component.onCompleted: {
        for (var i = 0; i < sequence.length; i++) {
            if (i + 1 !== sequence.length)
                registerNextFocus(sequence[i], sequence[i + 1])
            else
                registerNextClick(sequence[i], accept)
        }
        function registerNextFocus(obj, nextObj) {
            var focusFunc = nextObj.myForceActiveFocus || nextObj.forceActiveFocus
            obj.accepted.connect(function () {
                focusFunc()
            })
        }
        function registerNextClick(obj, clickObj) {
            obj.accepted.connect(function () {
                clickObj.clicked(1)
            })
        }
        sequence[0].forceActiveFocus()
    }
}
